package com.itheima.sc.web.order;

import cn.hutool.core.convert.Convert;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.order.OmsOrderReturnApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@RestController
@RequestMapping("returnApply")
public class OmsOrderReturnApplyController {

    /**
     * 分页查询退货申请
     */

    @Autowired
    OmsOrderReturnApplyService omsOrderReturnApplyService;
    @GetMapping("list")
    public Result list(
            @RequestParam Map map
    ){
        Integer pageNum = Convert.toInt( map.get("pageNum"));
        Integer pageSize = Convert.toInt( map.get("pageSize"));

        return omsOrderReturnApplyService.listOmsOrderReturnApply(pageNum,pageSize,map);
    }


    @PostMapping("delete")
    public Result deletOrderReturnApply(@RequestParam Map<String,String> map){
        String ids = map.get("ids");
        String[] split = ids.split(",");
        ArrayList<Long> idss = new ArrayList<>();
        for (String s : split) {
            idss.add(Convert.toLong(s));
        }
        return omsOrderReturnApplyService.deletByIds(idss);

    }
//修改退货申请状态
    @PostMapping("update/status/{id}")
    public Result receiverInfo(
            @PathVariable Long id,
            @RequestBody Map<String,String> map){

        return omsOrderReturnApplyService.updateStatus(id,map);
    }

    //获取详情
    @GetMapping("{id}")
    public Result getOmsOrderReturnApplyById(@PathVariable Long id){
        return omsOrderReturnApplyService.getById(id);
    }



}
